package client.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;

public class AccountLoginFrame extends JFrame{
	
	private JPanel mainPanel;
	private JTextArea usernameEntry;
	private JPasswordField passwordEntry;
	private JButton loginButton;
	private JButton cancelButton;
	private JLabel usernameLabel;
	private JLabel passwordLabel;
	
	private String storedUsername;
	private String storedPassword;
	
	//private LobbyClient mClient;
	
	public AccountLoginFrame(){
		super("Account Login");
		this.setSize(400,200);
//		this.mClient = client;
		createUI();
	}
	
	public void createUI(){
		mainPanel = new JPanel();
		usernameEntry = new JTextArea();
		usernameEntry.setSize(50,50);
		passwordEntry = new JPasswordField();
		passwordEntry.setSize(50,50);
		GridBagLayout gridBag = new GridBagLayout();
		mainPanel.setLayout(gridBag);
		
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.gridx = 0;		//Leading edge should line up with left side of panel
		gbc.gridwidth = GridBagConstraints.REMAINDER;	//Width should be the whole row
		usernameLabel = new JLabel("Username");
		gridBag.setConstraints(usernameLabel,gbc);
		mainPanel.add(usernameLabel);
		
		gridBag.setConstraints(usernameEntry,gbc);
		mainPanel.add(usernameEntry);
		
		passwordLabel = new JLabel("Password");
		gridBag.setConstraints(passwordLabel,gbc);
		mainPanel.add(passwordLabel);
		
		gridBag.setConstraints(passwordEntry,gbc);
		mainPanel.add(passwordEntry);
		
		gbc.gridwidth = GridBagConstraints.RELATIVE;	//Reset width, should start a new row
		gbc.gridx = GridBagConstraints.RELATIVE;		//Reset where leading edge lines up
		gbc.weightx = 0.5;
		loginButton = new JButton("Login");
		gridBag.setConstraints(loginButton,gbc);
		loginButton.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent me){
				System.out.println("Login Clicked");
				storedUsername = usernameEntry.getText();
				storedPassword = String.valueOf(passwordEntry.getPassword());
				AccountLoginFrame.this.setVisible(false);
			}
		});
		mainPanel.add(loginButton);
		
		gbc.gridwidth = GridBagConstraints.REMAINDER;	//Same row as login button, take up the remaining width
		cancelButton = new JButton("Cancel");
		gridBag.setConstraints(cancelButton,gbc);
		cancelButton.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent me){
				System.out.println("Cancel Clicked");
				System.exit(2);
			}
		});
		mainPanel.add(cancelButton);
		
		this.add(mainPanel);
	}
	
	public static void main(String[] argv){
		AccountLoginFrame alf = new AccountLoginFrame();
		alf.setVisible(true);
	}
}

